<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head >

    </h:head>
    <h:body onload="document.getElementById('form1:codigo').focus()">
        <ui:composition template="templateTeste.xhtml">
            <ui:define name="centro">
                <p:messages globalOnly="true" showDetail="true"/>
                <!--h2><h:messages globalOnly="true" layout="table" showDetail="true" infoStyle="color: blue" warnStyle="color: yellow" errorStyle="color: red"/></h2-->
                <h:form id="form1">
                    <h:inputHidden value="#{manterProdutoBean.produto.id}"/>

                    <h:outputText value="#{mens.CODIGO}" style="margin-left: 10px" styleClass="outputText"/>
                    <p:inputText id="codigo" value="#{manterProdutoBean.codigo}" required="true" size="30">
                     <!--   <f:validateRegex pattern="[0-9]" for="codigo" />-->
                        <f:validateLongRange minimum="1" maximum="999999999" for="codigo"/>
                    </p:inputText>


                    <p:message for="codigo"/>
                    <br/>

                    <h:outputText value="#{mens.NOME}" style="margin-left: 28px"  styleClass="outputText"/>
                    <p:inputText id="nome" value="#{manterProdutoBean.produto.nome}" required="true" size="30" />
                    <p:message for="nome"/>
                    <br/>

                    <h:outputText value="#{mens.PRECO}" style="margin-left: 20px" styleClass="outputText"/>
                    <p:inputText id="preco" required="true" value="#{manterProdutoBean.preco}" size="30" >
                        <f:validateRegex pattern="[0-9]+[.][0-9]+" for="preco" />
                        <f:validateDoubleRange minimum="0.01" maximum="99999.99" for="preco"/>
                    </p:inputText>
                    <p:message for="preco"/>
                    <br/>

                    <h:commandButton value="#{mens.INSERIR}" action="#{manterProdutoBean.create}" style="margin-left: 30px" />
                    <h:commandButton value="#{mens.ALTERAR}" action="#{manterProdutoBean.edit}" disabled="#{manterProdutoBean.naoSelecionouProduto}"/>
                    <h:commandButton value="#{mens.EXCLUIR}" action="#{manterProdutoBean.destroy}" disabled="#{manterProdutoBean.naoSelecionouProduto}"/>
                </h:form>

                <br/>
                <h:form>
                    <h:commandButton value="#{mens.PESQUISAR}" action="#{manterProdutoBean.findProdutoEntities}" style="margin-left: 30px"/>
                    <p:dataTable paginator="true" rows="4" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5" emptyMessage="#{mens.TABELA_VAZIA}" value="#{manterProdutoBean.produtos}" var="p" style="width:620px " rendered="#{manterProdutoBean.exibeTabela}">
                        <p:column style="width: 200px">
                            <f:facet name="header">#{mens.CODIGO}</f:facet>

                            <h:commandLink style="color: maroon; font-weight: bolder" value="#{p.codigo}" action="paginaManterProduto.xhtml">
                                <f:setPropertyActionListener value="#{p.codigo}" target="#{manterProdutoBean.codigo}"/>
                                <f:setPropertyActionListener value="#{p.nome}" target="#{manterProdutoBean.produto.nome}"/>
                                <f:setPropertyActionListener value="#{p.preco}" target="#{manterProdutoBean.preco}"/>
                                <f:setPropertyActionListener value="#{p.id}" target="#{manterProdutoBean.produto.id}"/>
                                <f:setPropertyActionListener value="false" target="#{manterProdutoBean.naoSelecionouProduto}"/>
                            </h:commandLink>


                        </p:column>
                        <p:column style="width: 220px">
                            <f:facet name="header">#{mens.NOME}</f:facet>
                            <h:outputText value="#{p.nome}"/>
                        </p:column>
                        <p:column style="width: 200px">
                            <f:facet name="header">#{mens.PRECO}</f:facet>
                            <h:outputText value="#{p.preco}"/>
                        </p:column>
                    </p:dataTable>
                </h:form>


            </ui:define>
        </ui:composition>
    </h:body>
</html>

